package com.ysoo.demo;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@SpringBootApplication
@ComponentScan(basePackages={"com.ysoo"})
public class SummerApplication extends SpringBootServletInitializer {

	// 从 application.properties 中读取配置，如取不到默认值为Hello

	@Value("${application.hello:Hello}")
	private String hello;

	public static void main(String[] args) {
		SpringApplication.run(SummerApplication.class, args);
//		SpringApplicationBuilder builder = new SpringApplicationBuilder(SummerApplication.class);
//		//修改Banner的模式为OFF
//		builder.bannerMode(Banner.Mode.valueOf("SUMMER")).run(args);
	}

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
		return builder.sources(SummerApplication.class);
	}


	@RequestMapping(value = "/",produces = "text/plain;charset=UTF-8")
	String index(){
		return "Hello Spring Boot!";
	}





	@RequestMapping("/index")

	public String helloJsp(Map<String, Object> map) {

		System.out.println("HelloController.helloJsp().hello=" + hello);
		map.put("hello", hello);
		return "index";



	}
}
